package com.zw.pdm.module.designtask.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.module.designtask.service.DsnConIntService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 控制意图
 * <p>
 * 权限：
 * dsn:intent:upload 控制意图文件上传
 * dsn:intent:download 控制意图文件下载
 * dsn:intent:delFile 控制意图文件删除
 * @Author: China.wsg
 * @Date: 2020/11/03 18:21
 */
@Controller
@RequestMapping("/designTask/conInt")
@SuppressWarnings("all")
public class DsnConIntController extends BaseController {

    @Autowired
    private DsnConIntService dsnConIntService;

    /**
     * 导入
     *
     * @param file 导入文件
     * @return JsonResult
     */
    @ResponseBody
    @PostMapping("/uploadFile")
    @RequiresPermissions(value = {"dsn:intent:upload", "dsn:proDebug:upload"}, logical = Logical.OR)
    public JsonResult uploadFile(@RequestParam("proId") Integer proId, @RequestParam("file") MultipartFile file
            , @RequestParam("fileContent") String fileContent,@RequestParam("fileType") Integer fileType) {
        dsnConIntService.uploadFile(file, proId,fileContent,fileType);
        return success();
    }

    /**
     * 下载文件
     */
    @GetMapping("/download")
    @RequiresPermissions({"dsn:intent:download"})
    public void download(HttpServletResponse response, @RequestParam("ids") Integer[] ids, @RequestParam("proCode") String proCode) {
        dsnConIntService.download(response, ids, proCode);
    }

    /**
     * 删除产品结构
     */
    @ResponseBody
    @PostMapping("/delConIntent")
    @RequiresPermissions({"dsn:intent:delFile"})
    public JsonResult conIntentDel(@RequestParam("ids") Integer[] ids) {
        return jsonResult(dsnConIntService.delConIntentById(ids));
    }

}
